﻿using System.Reflection;
using Autofac;
using STX.Lib.Net;
using STX.Service;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using STX.Domain;

namespace ServiceTest
{
    
    
    /// <summary>
    ///这是 TabBlackListServiceTest 的测试类，旨在
    ///包含所有 TabBlackListServiceTest 单元测试
    ///</summary>
    [TestClass()]
    public class TabBlackListServiceTest:BaseTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下 文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Update 的测试
        ///</summary>
        [TestMethod()]
        public void UpdateTest()
        {
            var service = container.Resolve<TabBlackListService>();
            var entity = new TabBlackList
            {
                Id  = 12,
                BlockScopeValue = (int)(TabBlackList.BlockScope.Front | TabBlackList.BlockScope.Admin),
                EndTime = DateTime.Now,
                StartTime = DateTime.Now.AddDays(-30),
                IpAddress = "127.0.0.12"                    
            };
            //service.Update(entity);

            Assert.IsTrue(service.Update(entity));
            //Assert.
        }


        [TestMethod()]
        public void AddCurrentToBlackListTest()
        {
            var service = container.Resolve<TabBlackListService>();
            service.AddCurrentToBlackList(TabBlackList.BlockScope.Admin,20);
            Assert.AreNotEqual(0, 1, "11");
        }

        [TestMethod()]
        public void AddTest()
        {
            var service = container.Resolve<TabBlackListService>();
            var entity = new TabBlackList
            {
                BlockScopeValue = (int)TabBlackList.BlockScope.Admin,
                EndTime = DateTime.Now,
                StartTime = DateTime.Now.AddDays(-30),
                IpAddress = "127.0.0.99"
            };
            Assert.AreNotEqual(0, service.Add(entity), "添加未成功");
        }
    }
}
